Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metaclass conflict check improvements #17682

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

robsdedude
Copy link

This PR fixes some points of #14033:

  • Give metaclass errors to their own error code (I chose metaclass).
  • Document shortcomings of and workarounds for mypy's metaclass handling.

I didn't attempt to fix that mypy follows the logic for determining the metaclass as documented whereas it should follow what the interpreter is actually doing (#14033 (comment)). I think such a change is better kept as a separate PR, which is why I don't want to close the issue with this PR.

This comment has been minimized.

This comment has been minimized.

@robsdedude
Copy link
Author

The tests passed locally. I'm not quite sure what's going on. I'll dig deeper when I'm back from vacation in about a week.

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

artigraph (https://github.com/artigraph/artigraph)
- src/arti/versions/__init__.py:17: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/versions/__init__.py:21: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/versions/__init__.py:31: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/versions/__init__.py:61: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/versions/__init__.py:75: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/statistics/__init__.py:8: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/annotations/__init__.py:8: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:26: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:44: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:48: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:61: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:70: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:74: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:78: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:82: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:86: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:90: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:94: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:98: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:130: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:134: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:138: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:142: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:147: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:151: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:155: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:159: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:163: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:169: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ src/arti/versions/__init__.py:17: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/versions/__init__.py:21: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/versions/__init__.py:31: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/versions/__init__.py:61: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/versions/__init__.py:75: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/statistics/__init__.py:8: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/annotations/__init__.py:8: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/types/__init__.py:26: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/types/__init__.py:44: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/types/__init__.py:48: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/types/__init__.py:61: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/types/__init__.py:70: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/types/__init__.py:74: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/types/__init__.py:78: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/types/__init__.py:82: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/types/__init__.py:86: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]
+ src/arti/types/__init__.py:90: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: arti.internal.models.ModelMeta, pydantic._internal._model_construction.ModelMetaclass  [metaclass]

... (truncated 356 lines) ...

ibis (https://github.com/ibis-project/ibis)
- ibis/common/collections.py:280: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ ibis/common/collections.py:280: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: abc.ABCMeta, ibis.common.bases.AbstractMeta  [metaclass]
- ibis/common/collections.py:305: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ ibis/common/collections.py:305: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: ibis.common.bases.AbstractMeta, abc.ABCMeta  [metaclass]
- ibis/common/tests/test_patterns.py:273: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ ibis/common/tests/test_patterns.py:273: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: abc.ABCMeta, ibis.common.bases.AbstractMeta  [metaclass]
- ibis/common/tests/test_patterns.py:486: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ ibis/common/tests/test_patterns.py:486: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: abc.ABCMeta, ibis.common.bases.AbstractMeta  [metaclass]
- ibis/common/tests/test_patterns.py:1211: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ ibis/common/tests/test_patterns.py:1211: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: ibis.common.bases.AbstractMeta, abc.ABCMeta  [metaclass]

comtypes (https://github.com/enthought/comtypes)
- comtypes/typeinfo.py:194: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/typeinfo.py:194: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/typeinfo.py:289: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/typeinfo.py:289: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/typeinfo.py:406: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/typeinfo.py:406: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/typeinfo.py:450: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/typeinfo.py:450: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/typeinfo.py:455: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/typeinfo.py:455: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/typeinfo.py:459: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/typeinfo.py:459: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/typeinfo.py:470: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/typeinfo.py:470: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/typeinfo.py:1073: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/typeinfo.py:1073: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/typeinfo.py:1090: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/typeinfo.py:1090: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/errorinfo.py:10: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/errorinfo.py:10: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/errorinfo.py:21: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/errorinfo.py:21: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/errorinfo.py:38: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/errorinfo.py:38: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/automation.py:642: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/automation.py:642: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/automation.py:777: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/automation.py:777: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/_post_coinit/unknwn.py:371: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/_post_coinit/unknwn.py:371: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - own metaclass comtypes._post_coinit.unknwn._compointer_meta is not a subclass of   [metaclass]
- comtypes/_post_coinit/unknwn.py:487: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/_post_coinit/unknwn.py:487: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - own metaclass comtypes._post_coinit.unknwn._cominterface_meta is not a subclass of _ctypes._CDataMeta  [metaclass]
- comtypes/_post_coinit/misc.py:47: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/_post_coinit/misc.py:47: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/_post_coinit/misc.py:62: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/_post_coinit/misc.py:62: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/persist.py:22: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/persist.py:22: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/persist.py:36: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/persist.py:36: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/persist.py:63: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/persist.py:63: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/persist.py:108: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/persist.py:108: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/persist.py:154: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/persist.py:154: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/persist.py:214: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/persist.py:214: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/connectionpoints.py:20: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
+ comtypes/connectionpoints.py:20: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - found metaclasses of bases: _ctypes._CDataMeta  [metaclass]
- comtypes/connectionpoints.py:25: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]

... (truncated 33 lines) ...

steam.py (https://github.com/Gobot1234/steam.py)
- steam/utils.py:432: error: Dynamic metaclass not supported for "StructIO"  [misc]
+ steam/utils.py:432: error: Dynamic metaclass not supported for "StructIO"  [metaclass]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant